import book.Book;
import user.*;
import utils.AnalyzingBook;

import java.lang.reflect.Proxy;
import java.util.Scanner;

import static constant.Constant.ALL_BOOK_FILE_NAME;
import static constant.Constant.CAPACITY;

public class LibrarySystem {
    public ProxyUser selectProxyRole(ProxyUser dzjProxyAdminUser,ProxyUser hzpProxyNormalUser,ProxyUser hhhProxyNormalUser){
        System.out.println(" 选择⻆⾊进⾏登录： ");
        System.out.println("1. 管理员\n2. 普通⽤⼾ (hzp)\n3. 普通⽤⼾ (hhh)\n4. 退出系统 \n");
        ProxyUser currentUser=null;
        Scanner scanner=new Scanner(System.in);
        int choice = scanner.nextInt();
        switch (choice){
            case 1:
                currentUser=dzjProxyAdminUser;
                break;
            case 2:
                currentUser=hzpProxyNormalUser;
                break;
           case 3:
                currentUser=hhhProxyNormalUser;
                break;
           case 4:
               System.out.println("退出系统");
               System.exit(0);
               default:
                   System.out.println("error");
        }
        return currentUser;
    }


    public static void main(String[] args) {
        IUserFactory adminFactory = new AdminUserFactory();
        IUserFactory normalFactory = new NormalUserFactory();
        User dzj = adminFactory.createUser("dzj",0);
        User hzp = normalFactory.createUser("hzp",1);
        User hhh = normalFactory.createUser("hhh",2);

        ProxyUser dzjProxyAdminUser=new ProxyUser(dzj);
        ProxyUser hzpProxyNormalUser=new ProxyUser(hzp);
        ProxyUser hhhProxyNormalUser=new ProxyUser(hhh);

        LibrarySystem librarySystem=new LibrarySystem();
        ProxyUser currentUser = librarySystem.selectProxyRole(dzjProxyAdminUser,hzpProxyNormalUser,hhhProxyNormalUser);
        while (true) {
            int choice = currentUser.getRealUser().display();
            currentUser.handleOperation(choice);
        }
    }
}
